extends Spatial

# only used in editor
export(bool) var use_static_body: bool = true
export(float) var strength: float = 1.0
export(float) var cycle: float = 3.0
export(float, 0.0, 1.0, 0.01) var phase: float = 0.0

onready var rigid_body: RigidBody = $RigidBody

func _ready():
	if not Engine.editor_hint:
		$EditorOnly.queue_free()
		if not use_static_body:
			var sb: StaticBody = $StaticBody
			sb.collision_layer = 0
			sb.collision_mask = 0

func _physics_process(delta):
	if abs(strength) > 1e-3 and cycle > 1e-3:
		phase = fmod(phase + delta / cycle, 1.0)
		var force: Vector3 = Vector3(0.0, 0.0, strength * cos(2.0 * PI * phase))
		rigid_body.add_central_force(global_transform.basis.xform(force))
